/*    */ package com.zimbra.cs.dav.service.method;
/*    */ 
/*    */ import com.zimbra.common.mime.ContentType;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.ByteUtil;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.dav.DavContext;
/*    */ import com.zimbra.cs.dav.DavException;
/*    */ import com.zimbra.cs.dav.resource.DavResource;
/*    */ import com.zimbra.cs.dav.service.DavMethod;
/*    */ import com.zimbra.cs.dav.service.DavServlet;
/*    */ import com.zimbra.cs.servlet.ETagHeaderFilter;
/*    */ import java.io.IOException;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class Get
/*    */   extends DavMethod
/*    */ {
/*    */   public static final String GET = "GET";
/*    */   
/*    */   public String getName()
/*    */   {
/* 41 */     return "GET";
/*    */   }
/*    */   
/*    */   protected boolean returnContent() {
/* 45 */     return true;
/*    */   }
/*    */   
/*    */   public void handle(DavContext ctxt) throws DavException, IOException, ServiceException
/*    */   {
/* 50 */     DavResource resource = ctxt.getRequestedResource();
/* 51 */     HttpServletResponse resp = ctxt.getResponse();
/* 52 */     String contentType = resource.getContentType(ctxt);
/* 53 */     if (contentType != null) {
/* 54 */       ContentType ct = new ContentType(contentType);
/* 55 */       if (ct.getParameter("charset") == null)
/* 56 */         ct.setParameter("charset", "utf-8");
/* 57 */       resp.setContentType(ct.toString());
/*    */     }
/* 59 */     if (resource.hasEtag()) {
/* 60 */       ctxt.getResponse().setHeader("ETag", resource.getEtag());
/* 61 */       ctxt.getResponse().setHeader(ETagHeaderFilter.ZIMBRA_ETAG_HEADER, resource.getEtag());
/*    */     }
/*    */     
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/* 72 */     if ((!returnContent()) || (!resource.hasContent(ctxt)))
/* 73 */       return;
/* 74 */     resp.setHeader("Content-Disposition", "attachment");
/* 75 */     ByteUtil.copy(resource.getContent(ctxt), true, ctxt.getResponse().getOutputStream(), false);
/* 76 */     resp.setStatus(ctxt.getStatus());
/* 77 */     ctxt.responseSent();
/* 78 */     if (ZimbraLog.dav.isDebugEnabled()) {
/* 79 */       StringBuilder sb = new StringBuilder("Response for DAV GET ").append(ctxt.getUri()).append("\n");
/* 80 */       if ((contentType != null) && (contentType.startsWith("text"))) {
/* 81 */         DavServlet.addResponseHeaderLoggingInfo(resp, sb);
/* 82 */         if (ZimbraLog.dav.isTraceEnabled()) {
/* 83 */           sb.append(new String(ByteUtil.getContent(resource.getContent(ctxt), 0), "UTF-8"));
/*    */         }
/* 85 */         ZimbraLog.dav.debug(sb);
/*    */       }
/*    */     }
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/service/method/Get.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */